package com.yxb.appointment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yxb.common.annotation.Log;
import com.yxb.common.core.controller.BaseController;
import com.yxb.common.core.domain.AjaxResult;
import com.yxb.common.enums.BusinessType;
import com.yxb.appointment.domain.MyAppointment;
import com.yxb.appointment.service.IMyAppointmentService;
import com.yxb.common.utils.poi.ExcelUtil;
import com.yxb.common.core.page.TableDataInfo;

/**
 * 我的预约Controller
 * 
 * @author 林德炫
 * @date 2025-03-29
 */
@RestController
@RequestMapping("/appointment/appointment")
public class MyAppointmentController extends BaseController
{
    @Autowired
    private IMyAppointmentService myAppointmentService;

    @GetMapping("/confirmAppointment/{appointmentId}")
    public Boolean confirmAppointment(@PathVariable("appointmentId")Long appointmentId)
    {
        return  myAppointmentService.confirmAppointment(appointmentId);
    }


    /**
     *  根据家长姓名查询预约信息
     * @param teacherName
     * @return
     */
    @GetMapping("/getListByTeacherName/{teacherName}")
    public List<MyAppointment> getListByTeacherName(
            @PathVariable("teacherName") String teacherName,
            @RequestParam(required = false) String status)
    {
        return myAppointmentService.getListByTeacherName(teacherName, status);
    }

    @GetMapping("/getListByParentName/{parentName}")
    public List<MyAppointment> getListByParentName(
            @PathVariable("parentName") String parentName,
            @RequestParam(required = false) String status)
    {
        return myAppointmentService.getListByParentName(parentName, status);
    }


    /**
     * 查询我的预约列表
     */
    @PreAuthorize("@ss.hasPermi('appointment:appointment:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyAppointment myAppointment)
    {
        startPage();
        List<MyAppointment> list = myAppointmentService.selectMyAppointmentList(myAppointment);
        return getDataTable(list);
    }

    /**
     * 导出我的预约列表
     */
    @PreAuthorize("@ss.hasPermi('appointment:appointment:export')")
    @Log(title = "我的预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyAppointment myAppointment)
    {
        List<MyAppointment> list = myAppointmentService.selectMyAppointmentList(myAppointment);
        ExcelUtil<MyAppointment> util = new ExcelUtil<MyAppointment>(MyAppointment.class);
        util.exportExcel(response, list, "我的预约数据");
    }

    /**
     * 获取我的预约详细信息
     */
    @PreAuthorize("@ss.hasPermi('appointment:appointment:query')")
    @GetMapping(value = "/{appointmentId}")
    public AjaxResult getInfo(@PathVariable("appointmentId") Long appointmentId)
    {
        return success(myAppointmentService.selectMyAppointmentByAppointmentId(appointmentId));
    }

    /**
     * 新增我的预约
     */
    @PreAuthorize("@ss.hasPermi('appointment:appointment:add')")
    @Log(title = "我的预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyAppointment myAppointment)
    {
        return toAjax(myAppointmentService.insertMyAppointment(myAppointment));
    }

    /**
     * 修改我的预约
     */
    @PreAuthorize("@ss.hasPermi('appointment:appointment:edit')")
    @Log(title = "我的预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyAppointment myAppointment)
    {
        return toAjax(myAppointmentService.updateMyAppointment(myAppointment));
    }

    /**
     * 删除我的预约
     */
    @PreAuthorize("@ss.hasPermi('appointment:appointment:remove')")
    @Log(title = "我的预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{appointmentIds}")
    public AjaxResult remove(@PathVariable Long[] appointmentIds)
    {
        return toAjax(myAppointmentService.deleteMyAppointmentByAppointmentIds(appointmentIds));
    }
}
